package com.itheima.consumer.listener;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.consumer.util.MailUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 发送邮件
 */
@Component
public class ShipTimeListener implements MessageListener {
    private static final ObjectMapper MAPPER = new ObjectMapper();

    @Override
    public void onMessage(Message message) {
        try {

            JsonNode jsonNode = MAPPER.readTree(message.getBody());
            // 获取队列中ids 消息
            String to = jsonNode.get("ids").asText();

            // 打印测试
            System.out.println("获取队列中消息：" + to);

            // 发送邮件
            //MailUtil.sendMsg(to,subject,content);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
